{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "ename": "ImportError",
     "evalue": "cannot import name 'AppProduct' from 'AppStoreConnect' (/Users/wangfan/sales-report/AppStoreConnect/__init__.py)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mImportError\u001b[0m                               Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[11], line 5\u001b[0m\n\u001b[1;32m      3\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01msqlalchemy\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m create_engine\n\u001b[1;32m      4\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mmatplotlib\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mpyplot\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mplt\u001b[39;00m\n\u001b[0;32m----> 5\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mAppStoreConnect\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m Subscription, AppProduct\n\u001b[1;32m      7\u001b[0m \u001b[38;5;66;03m# 创建AppDB实例\u001b[39;00m\n\u001b[1;32m      8\u001b[0m engine \u001b[38;5;241m=\u001b[39m create_engine(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmysql+pymysql://appconnect:pobxoj-Mopsy5-bycqac@47.116.122.58:3306/app\u001b[39m\u001b[38;5;124m'\u001b[39m)\n",
      "\u001b[0;31mImportError\u001b[0m: cannot import name 'AppProduct' from 'AppStoreConnect' (/Users/wangfan/sales-report/AppStoreConnect/__init__.py)"
     ]
    }
   ],
   "source": [
    "from AppDB import AppDB\n",
    "import pandas as pd\n",
    "from sqlalchemy import create_engine\n",
    "import matplotlib.pyplot as plt\n",
    "from AppStoreConnect import Subscription, AppProduct\n",
    "\n",
    "# 创建AppDB实例\n",
    "engine = create_engine('mysql+pymysql://appconnect:pobxoj-Mopsy5-bycqac@47.116.122.58:3306/app')\n",
    "\n",
    "# 获取从start_date到end_date的 订阅事件数据\n",
    "df = pd.read_sql('select * from subscription_event where event_date between \"2024-01-01\" and \"2024-2-29\"', engine)\n",
    "\n",
    "# 筛选出subscription_apple_id为'6449180970'的数据\n",
    "df = df[df['subscription_apple_id'] == AppProduct.Sub_Hearty_1_Year.name]\n",
    "\n",
    "\n",
    "activation_events = Subscription.activation_events\n",
    "\n",
    "# 筛选出event_type为'1'的数据\n",
    "df = df[df['event'] in activation_events]\n",
    "\n",
    "print(df[0])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "env",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
